 #include "sounds.h"

 void loadSong( char filename[200] )
{

 
 if ( jeu.musique != NULL )
 {
    Mix_HaltMusic();
    Mix_FreeMusic(jeu.musique);
 }

 
 jeu.musique = Mix_LoadMUS( filename );
 if (jeu.musique == NULL)
    {
        fprintf(stderr, "Can't read the music \n");
        exit(1);
    }

 
 
     if(Mix_PlayMusic(jeu.musique, -1)==-1)
     {
        printf("Mix_PlayMusic: %s\n", Mix_GetError());
     }


}


 void loadSound(void)
{

   jeu.jump_sound = Mix_LoadWAV("music/jump.wav");
   if (jeu.jump_sound == NULL)
    {
        fprintf(stderr, "Can't read the jump sound FX \n");
        exit(1);
    }

   jeu.attack_sound = Mix_LoadWAV("music/attack.wav");
   if (jeu.attack_sound == NULL)
    {
        fprintf(stderr, "Can't read the attack sound FX \n");
        exit(1);
    }

   jeu.run_sound = Mix_LoadWAV("music/run.wav");
   if (jeu.run_sound == NULL)
    {
        fprintf(stderr, "Can't read the run sound FX \n");
        exit(1);
    }

   jeu.star_sound = Mix_LoadWAV("music/star.wav");
   if (jeu.star_sound == NULL)
    {
        fprintf(stderr, "Can't read the star sound FX \n");
        exit(1);
    }
    jeu.mort_sound = Mix_LoadWAV("music/mort.wav");
   if (jeu.mort_sound == NULL)
    {
        fprintf(stderr, "Can't read the mort sound FX \n");
        exit(1);
    }
    jeu.win_sound = Mix_LoadWAV("music/winner.wav");
    if (jeu.win_sound == NULL)
    {
        fprintf(stderr, "Can't read the winner sound FX \n");
        exit(1);
    }
     jeu.loose_sound = Mix_LoadWAV("music/looser2.wav");
     if (jeu.loose_sound == NULL)
    {
        fprintf(stderr, "Can't read the looser sound FX \n");
        exit(1);
    }
     jeu.hit_sound = Mix_LoadWAV("music/hit.wav");
     if (jeu.hit_sound == NULL)
    {
        fprintf(stderr, "Can't read the hit sound FX \n");
        exit(1);
    }
     jeu.shuriken_sound = Mix_LoadWAV("music/shuri.wav");
     if (jeu.shuriken_sound == NULL)
    {
        fprintf(stderr, "Can't read the shuri sound FX \n");
        exit(1);
    }
    jeu.feu_sound = Mix_LoadWAV("music/fire.wav");
     if (jeu.feu_sound == NULL)
    {
        fprintf(stderr, "Can't read the feu sound FX \n");
        exit(1);
    }
    jeu.YouWin = Mix_LoadWAV("music/YouWin.wav");
     if (jeu.YouWin == NULL)
    {
        fprintf(stderr, "Can't read the YouWin sound FX \n");
        exit(1);
    }
   
 

}



void freeSound(void)
{

   Mix_FreeChunk(jeu.attack_sound);
   Mix_FreeChunk(jeu.run_sound);
   Mix_FreeChunk(jeu.jump_sound);
   Mix_FreeChunk(jeu.star_sound);
   Mix_FreeChunk(jeu.feu_sound);
   Mix_FreeChunk(jeu.shuriken_sound);
   Mix_FreeChunk(jeu.hit_sound);
   Mix_FreeChunk(jeu.loose_sound);
   Mix_FreeChunk(jeu.win_sound);
   Mix_FreeChunk(jeu.YouWin);
 
 
}


void playSoundFx(int type)
{

    switch (type)
    {

        case JUMP:
            Mix_PlayChannel(-1, jeu.jump_sound, 0);
        break;

        case ATTACK:
            Mix_PlayChannel(-1, jeu.attack_sound, 0);
        break;

        case RUN :
            Mix_PlayChannel(20, jeu.run_sound, 0);
        break;

        case STAR:
            Mix_PlayChannel(-1, jeu.star_sound, 0);
        break;
        case MORT:
            Mix_PlayChannel(-1, jeu.mort_sound, 0);
        break;

        case WIN:
            Mix_PlayChannel(-1, jeu.win_sound, 0);
        break;

        case LOOSE:
            Mix_PlayChannel(-1, jeu.loose_sound, 0);
        break;

        case HIT :
            Mix_PlayChannel(-1, jeu.hit_sound, 0);
        break;

        case SHURIKEN:
            Mix_PlayChannel(-1, jeu.shuriken_sound, 0);
        break;
        case FEU:
            Mix_PlayChannel(30, jeu.feu_sound, 0);
        break;
        case YOUWIN:
            Mix_PlayChannel(-1, jeu.YouWin, 0);
        break;


   }


}





